Ext.ns('journal');

/**
 * Manages states in the application. This is a singleton instance. Methods here are dependent on each other's
 * implementation.
 * 
 * @type LoggerProxy
 */
journal.LoggerFactory = (function() {

    //private variable
    var loggerCache = [];

    var LoggerProxy = function(category) {
        try {
            this.logger = new Log4js.getLogger(category);
            //this.logger.setLevel(Log4js.Level.ALL);
            this.logger.setLevel(Log4js.Level.INFO);
            this.logger.addAppender(new Log4js.BrowserConsoleAppender(this.logger));
        } catch (loggingnotsupported) {
            this.logger = {
                log : Ext.emptyFn,
                info : Ext.emptyFn,
                debug : Ext.emptyFn
            };
        }

        this.log = function(s) {
            this.logger.log(s);
        };
        this.debug = function(s) {
            this.logger.debug(s);
        };
        this.info = function(s) {
            this.logger.info(s);
        };
        this.error = function(s) {
            this.logger.error(s);
        };
    };

    //main object returned
    return {
        getLogger : function(category) {
            if (loggerCache[category] == null) {
                loggerCache[category] = new LoggerProxy(category);
            }
            return loggerCache[category];
        }
    };
})();
